package com.moran.controller;

import ai.z.openapi.ZhipuAiClient;
import ai.z.openapi.core.Constants;
import ai.z.openapi.service.image.CreateImageRequest;
import ai.z.openapi.service.image.ImageResponse;
import ai.z.openapi.service.image.ImageResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 图像模型
 *
 */
@RestController
public class ImageController {

    @Value("${spring.ai.zhipuai.base-url}")
    private String baseUrl;

    @Value("${spring.ai.zhipuai.api-key}")
    private String apiKey;

    @Value("${spring.ai.zhipuai.embedding.options.model}")
    private String embeddingModel;

    @RequestMapping("/image")
    public ImageResult image(String text) {
        // 初始化客户端
        ZhipuAiClient client = ZhipuAiClient.builder()
                .baseUrl(baseUrl)
                .apiKey(apiKey)
                .build();

        CreateImageRequest request = CreateImageRequest.builder()
                .model(Constants.ModelCogView4250304)
                .prompt(text)
                .size("1024x1024")
                .build();

        ImageResponse response = client.images().createImage(request);
        return response.getData();
    }

}
